<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单编号" prop="num">
        <el-input
          v-model="queryParams.num"
          placeholder="请输入订单编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     
      <el-form-item label="预约时间">
        <el-date-picker
          v-model="daterangeOrderTime"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
     
     
      <el-form-item label="接单人" prop="receiveName">
        <el-input
          v-model="queryParams.receiveName"
          placeholder="请输入接单人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="接单电话" prop="receivePhone">
        <el-input
          v-model="queryParams.receivePhone"
          placeholder="请输入接单人电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option label="全部" value="" />
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          ></el-option>
        </el-select>
        
      </el-form-item>
     
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
     
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
		      :loading="loading"
          @click="handleAdd"
        >下单</el-button>
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['business:order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="expand" width="55" align="center" >
        <template slot-scope="scope">
          <el-row :gutter="20">
            <el-col :span="8">
              <el-card class="box-card">
                <div slot="header" class="clearfix">
                  <span>服务地址</span>
                </div>
                <el-form  label-width="80px">
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="用户" prop="userName">
                        {{scope.row.orderAddress.userName}}
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="电话" prop="userTelephone">
                        {{scope.row.orderAddress.userTelephone}}
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20">
                    <el-col :span="24">
                      <el-form-item label="详细地址" prop="detail">
                        {{scope.row.orderAddress.detail}}
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
              </el-card>
            </el-col>
            <el-col :span="16">
              <el-card>
                <el-tabs >
                  <el-tab-pane label="支付记录">
                    <el-table v-loading="loading" :data="scope.row.paymentList">
                      <el-table-column label="支付金额" align="center" prop="amount" />
                      <el-table-column label="支付方式" align="center" prop="payWay" />
                      <el-table-column label="交易流水号" align="center" prop="transNo" />
                      <el-table-column label="类型" align="center" prop="payType" />
                      <el-table-column label="主题" align="center" prop="subject" />
                      <el-table-column label="内容" align="center" prop="body" />
                      <el-table-column label="支付状态" align="center" prop="status" >
                        <template slot-scope="scope">
                          <el-tag v-if="scope.row.status == 1" type="success" size="mini">已支付</el-tag>
                          <el-tag v-else type="danger" size="mini">未支付</el-tag>
                        </template>
                      </el-table-column>
                      <el-table-column label="支付时间" align="center" prop="successTime" width="180">
                        <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.successTime) }}</span>
                        </template>
                      </el-table-column>
                      <!-- <el-table-column label="操作" align="center" width="100" class-name="small-padding fixed-width">
                        <template slot-scope="scope1">
                          <div style="text-align:left;">
                            <el-button
                              size="mini"
                              type="text" v-if="scope1.row.status == 0 "
                              @click="handleCreatePay(scope1.row)"
                            >去支付</el-button>            
                          </div> 
                         
                        </template>
                      </el-table-column>      -->
                      
                    </el-table>
                  </el-tab-pane>
                  <el-tab-pane label="抢单记录">
                    <el-table v-loading="loading" :data="scope.row.receiveList" >
                      <el-table-column label="抢单人" align="center" prop="userName" />
                      <el-table-column label="联系电话" align="center" prop="userTelephone" />
                      <el-table-column label="抢单时间" align="center" prop="createTime" width="180">
                        <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.createTime) }}</span>
                        </template>
                      </el-table-column>
                      <el-table-column label="备注" align="center" prop="remark" />   
                      <el-table-column label="状态" align="center" prop="status" >
                        <template slot-scope="scope">
                          <el-tag v-if="scope.row.status == 1" type="success" size="mini">已确认</el-tag>
                          <el-tag v-else type="danger" size="mini">未确认</el-tag>
                        </template>
                      </el-table-column>
                      <el-table-column label="操作" align="center" width="100" class-name="small-padding fixed-width">
                        <template slot-scope="scope1">
                          <div style="text-align:left;">
                            <el-button
                              size="mini"
                              type="text" v-if="scope1.row.status == 0 && scope.row.status == 5"
                              icon="el-icon-edit"
                              @click="handleReceiveOrder(scope1.row)"
                            >确认接单</el-button>            
                          </div> 
                         
                        </template>
                      </el-table-column>                   
                    </el-table>
                  </el-tab-pane>
                  
                  
                  <el-tab-pane label="检查记录">
                    <el-table v-loading="loading" :data="scope.row.checkList" >
                      <el-table-column label="地址" align="center" prop="address" />                      
                      <el-table-column label="图片" align="center" prop="imgUrl" >
                        <template slot-scope="scope">
                          <el-image v-if="scope.row.imgUrl"
                            style="width: 100px; height: auto"
                            :src="scope.row.imgUrl" 
                            :preview-src-list="[scope.row.imgUrl]">
                          </el-image>
                        </template>
                      </el-table-column>
                      <el-table-column label="结论" align="center" prop="remark" />
                    </el-table>
                  </el-tab-pane>
                  <el-tab-pane label="服务记录">
                    <el-table v-loading="loading" :data="scope.row.serviceList" >
                      <el-table-column label="服务人员" align="center" prop="receiveName" />
                      <el-table-column label="服务开始时间" align="center" prop="beginTime" width="180">
                        <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.beginTime) }}</span>
                        </template>
                      </el-table-column>
                      <el-table-column label="服务结束时间" align="center" prop="endTime" width="180">
                        <template slot-scope="scope">
                          <span>{{ parseTime(scope.row.endTime) }}</span>
                        </template>
                      </el-table-column>
                      <el-table-column label="图片" align="center" prop="imgUrl" >
                        <template slot-scope="scope">
                          <el-image v-if="scope.row.imgUrl"
                            style="width: 100px; height: auto"
                            :src="scope.row.imgUrl" 
                            :preview-src-list="[scope.row.imgUrl]">
                          </el-image>
                        </template>
                      </el-table-column>
                      <el-table-column label="备注" align="center" prop="remark" />
                    </el-table>
                  </el-tab-pane>
                  <el-tab-pane label="评价记录">
                  </el-tab-pane>
                </el-tabs>
                
              </el-card>
              
            </el-col>
          </el-row>
          
        </template>
      </el-table-column>
      <el-table-column label="订单编号" align="center" width="170" prop="num" >
        <template slot-scope="scope">
          <el-button
              type="text"
              @click="handleShow(scope.row)"
            >{{scope.row.num}}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="订单信息" align="center" prop="detail" />
      <el-table-column label="预约时间" align="center" prop="orderTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderTime) }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="联系人" align="center" prop="username" /> -->
      <!-- <el-table-column label="联系电话" align="center" prop="telephone" /> -->
      <el-table-column label="接单人" align="center" prop="receiveName" />
      <el-table-column label="接单电话" align="center" prop="receivePhone" />
      <el-table-column label="接单限制" align="center" prop="receiveLimit" />
      <el-table-column label="所属公司" align="center" prop="company" />
      <el-table-column label="所属代理" align="center" prop="proxy" />
      <!-- <el-table-column label="属性" align="center" prop="attribute" /> -->
      <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat"  width="80"  />
      <el-table-column label="备注" align="center" prop="remark" />
      <!-- <el-table-column label="应付" align="center" prop="payable" /> -->
      <!-- <el-table-column label="实付" align="center" prop="pay" /> -->
      <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <div style="text-align:left;">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleShow(scope.row)"
            >详情</el-button>           
          
            <el-button
              size="mini"
              type="text" v-if="scope.row.status == 0"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['business:order:remove']"
            >删除</el-button>
          </div>
          
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="50%" >    
      <div v-if="payStep == 0">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px" :disabled="disabled">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="服务信息" prop="attribute">
                <el-input v-model="form.attribute" placeholder="请选择服务" :readonly="true" >
                  <el-button slot="append" icon="el-icon-search" @click="openSelectAttribute"></el-button>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="单价" prop="price">
                <el-input  v-model="form.price" placeholder="请输入价格" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
             <el-form-item label="数量" prop="number">
                <el-input type="number" v-model="form.number" placeholder="请输入数量" @input="handleNumberInput" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="订单信息" prop="detail">
                <el-input type="textarea" :rows="2" v-model="form.detail" placeholder="请输入订单信息" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="预约时间" prop="orderTime">
                <el-date-picker clearable size="small"
                  v-model="form.orderTime"
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  placeholder="选择预约时间">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">              
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="选择地址" prop="address">
                <el-input v-model="form.address" placeholder="请选择地址" :readonly="true"  >
                  <el-button slot="append" icon="el-icon-search" @click="openSelectAddress"></el-button>
                </el-input>
              </el-form-item>
            </el-col>          
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="联系人" prop="username">
                <el-input v-model="form.username" placeholder="请输入联系人姓名" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系电话" prop="telephone">
                <el-input v-model="form.telephone" placeholder="请输入联系人电话" />
              </el-form-item>
            </el-col>
          </el-row>
          
          <!-- <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="接单人" prop="receiveName">
                <el-input v-model="form.receiveName" placeholder="请选择接单人" :readonly="true"  >
                  <el-button slot="append" icon="el-icon-search" @click="openSelectReceive"></el-button>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="接单电话" prop="receivePhone">
                <el-input v-model="form.receivePhone" placeholder="请输入接单人电话" :readonly="true" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="所属公司" prop="company">
                <el-input v-model="form.company" placeholder="请输入接单人所属公司" />
              </el-form-item>        
            </el-col>
            <el-col :span="12">
              <el-form-item label="所属代理" prop="proxy">
                <el-input v-model="form.proxy" placeholder="请输入接单人所属代理" />
              </el-form-item>
            </el-col>
          </el-row> -->
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="应付" prop="payable">
                <el-input v-model="form.payable" placeholder="请输入应付" :readonly="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="实付" prop="pay">
                <el-input v-model="form.pay" placeholder="请输入实付" :readonly="true"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="支付方式" prop="detailsId">
                <el-radio-group v-model="form.detailsId" >
                  <el-radio label="1" border>支付宝</el-radio>
                  <el-radio label="2" border disabled>微信支付</el-radio >
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
             
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="备注" prop="remark">
                <el-input type="textarea" :rows="2" v-model="form.remark" placeholder="请输入备注" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align:center;">
          <el-button type="primary" :loading="payloading"  @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      
        <select-attribute ref="selectAttrForm"  v-if="attrOpen" @finishSelected="finishSelectAttr"></select-attribute>
        <select-receive ref="selectReceiveForm"  v-if="receiveOpen" @finishSelected="finishSelectReceive"></select-receive>
        <select-address ref="selectAddressForm"  v-if="addressOpen" @finishSelected="finishSelectAddress"></select-address> 
      </div>       
      <div v-if="payStep == 1">
        <el-form ref="form" :model="form"  label-width="120px" :disabled="true">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="订单编号" prop="num">
                <el-input v-model="form.num"  :readonly="true" > </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="服务信息" prop="attribute">
                <el-input v-model="form.attribute"  :readonly="true" > </el-input>
              </el-form-item>
            </el-col>
          </el-row>
         
        </el-form>
        <div style="text-align:center;">
          <h2>扫码支付：￥{{form.pay}}</h2>
          <vue-qr :text="payQrcodeUrl" :margin="0" colorDark="#f67b29" colorLight="#fff"  :logoScale="0.3" :size="300"></vue-qr>
          <h3>二维码有效期：30:00 分钟</h3>
        </div>
      </div>
            
    </el-dialog>

    <distribute-receive ref="distributeReceiveForm"  v-if="distributeOpen" @finishSelected="finishDistributeReceive"></distribute-receive>
    <finish-order ref="finishOrderForm" v-if="finishOpen" @finishSelected="finishOrderSelected" ></finish-order>
    <show-order ref="showOrderForm" v-if="showOpen" ></show-order>
    
  </div>
</template>

<script>
import { listMyPublishOrder, getOrder, delOrder, addOrder, updateOrder, exportOrder, createPay } from "@/api/business/order";
import { listPayment, getPayment, delPayment, addPayment, updatePayment, exportPayment } from "@/api/order/payment";
import { selectReceive} from "@/api/order/receive";
import SelectAttribute from './selectAttribute';
import SelectReceive from './selectReceive';
import SelectAddress from './selectAddress';
import DistributeReceive from './distributeReceive';
import FinishOrder from './finishOrder';
import ShowOrder from './showOrder';
import VueQr from 'vue-qr';

export default {
  name: "Order",
  components: {
    VueQr,
    SelectAttribute,
    SelectReceive,
    SelectAddress,
    DistributeReceive,
    FinishOrder,
    ShowOrder
  },
  data() {
 
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      payloading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单管理表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      payQrcodeUrl: "null",
      payStep: 0,
      // 是否显示弹出层
      open: false,
      disabled: false,
      attrOpen: false,
      receiveOpen: false,
      addressOpen: false,
      distributeOpen: false,
      finishOpen: false,
      showOpen: false,
      // 预约时间时间范围
      daterangeOrderTime: [],
      // 创建人名称时间范围
      daterangeCreateTime: [],
      // 状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        num: null,
        detail: null,
        orderTime: null,
        userId: null,
        username: null,
        telephone: null,
        receiveId: null,
        receiveName: null,
        receivePhone: null,
        receiveLimit: null,
        group: null,
        attribute: null,
        status: null,
        createName: null,
        createId: null,
        createTime: null,
        payable: null,
        pay: null,
        payMethod: null,
        payType: 1
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        attribute: [
          { required: true, message: "服务信息不能为空", trigger: "blur" }
        ],
        orderTime: [
          { required: true, message: "预约时间不能为空", trigger: "blur" }
        ],
        detail: [
          { required: true, message: "订单信息不能为空", trigger: "blur" }
        ],
        username: [
          { required: true, message: "联系人不能为空", trigger: "blur" }
        ],
        telephone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
        receiveName: [
          { required: true, message: "接单人不能为空", trigger: "blur" }
        ],
        receivePhone: [
          { required: true, message: "接单电话不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("tb_order_status").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    
    /** 查询订单管理列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeOrderTime && '' != this.daterangeOrderTime) {
        this.queryParams.params["beginOrderTime"] = this.daterangeOrderTime[0];
        this.queryParams.params["endOrderTime"] = this.daterangeOrderTime[1];
      }
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listMyPublishOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        num: null,
        detail: null,
        orderTime: null,
        userId: null,
        username: null,
        telephone: null,
        receiveId: null,
        receiveName: null,
        receivePhone: null,
        receiveLimit: null,
        group: null,
        attribute: null,
        status: 0,
        remark: null,
        createName: null,
        createId: null,
        createTime: null,
        payable: null,
        pay: null,
        payMethod: null,
        number: 1,
        detailsId: '1',
        address: null,
        addressId: null,
        orderAddress: {
          address: null
        }
      };
      this.resetForm("form");
      this.payStep = 0;
      this.payloading = false;
    },
    // 字典状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeOrderTime = [];
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    openSelectAttribute(){
      this.attrOpen = true;
      this.$nextTick(()=>{
        this.$refs['selectAttrForm'].init();
      });
      
    },
    finishSelectAttr(data){
      this.form.attribute = data.name;
      this.form.tags = data.tags;
      this.form.price = data.price;
      this.form.attrId = data.id;

      this.form.payable = Number(this.form.price) * Number(this.form.number);
      this.form.pay = this.form.payable;
    },
    handleNumberInput(){
      if (this.form.price) {
        this.form.payable = Number(this.form.price) * Number(this.form.number);
        this.form.pay = this.form.payable;
      }
      
    },
    openSelectReceive(){
      this.receiveOpen = true;
      this.$nextTick(()=>{
        this.$refs['selectReceiveForm'].init();
      });
    },
    finishSelectReceive(data){
      console.log(data)
      this.form.receiveId = data.userId;
      this.form.receiveName = data.nickName;
      this.form.receivePhone = data.phonenumber;
      //
      this.form.proxyId = data.proxyId;
      this.form.proxy = data.proxy?.name;
      this.form.companyId = data.companyId;
      this.form.company = data.company?.name;
    },
    openSelectAddress(){
      this.addressOpen = true;
      this.$nextTick(()=>{
        this.$refs['selectAddressForm'].init();
      });
    },
    finishSelectAddress(data){
      console.log(data)
      this.form.orderAddress = data;
      this.form.address = data.area + data.detail;
      this.form.addressId = data.id;
      //
      this.form.userId = data.userId;
      this.form.username = data.userName;
      this.form.telephone = data.userTelephone;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrder(id).then(response => {
        this.form = response.data;
        this.form.address = response.data.orderAddress.detail;
        this.open = true;
        this.title = "订单管理";
      });
    },
    handleShow(row){
      this.showOpen = true;
      this.$nextTick(() => {
        this.$refs['showOrderForm'].init(row);
      });
    },
   
    openDistributeReceive(row){
      this.distributeOpen = true;
      this.$nextTick(()=>{
        this.$refs['distributeReceiveForm'].init(row);
      });
    },
    finishDistributeReceive(data){
      this.getList();
    },
    finishOrder(row){
      this.finishOpen = true;
      this.$nextTick(()=>{
        this.$refs['finishOrderForm'].init(row);
      });
    },
    finishOrderSelected(data){
      this.getList();
    },
    /** 提交按钮 */
    submitForm() {     
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.payloading = true;
          
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.status = 0;//已下单
            this.form.payWay = "PAGE";
            this.form.payType = "aliPay";
            addOrder(this.form).then(response => {
              console.log(response)
              if (response.code == 200) {
                this.form.num = response.data.orderNo;
                createPay({
                  detailsId: this.form.detailsId,
                  wayTrade: this.form.payWay,
                  price: this.form.pay,
                  id: response.data.id
                }).then(res => {
                  console.log(res)
                  this.payStep = 1;
                  this.payQrcodeUrl = res;
                }).then(() => {
                  this.checkPayStatusTask = setInterval(() => {
                    this.checkPayStatus(response.data.id);
                  }, 5000);
                });
              }
            });
          }
        }
      });
    },
    handleCreatePay(row) {
      var detailsId = 1;//alipay 
      var wayTrade = row.payType;
      createPay({
        detailsId: detailsId,
        wayTrade: wayTrade,
        price: row.amount
      }).then(res => {
        console.log(res)
        this.payStep = 1;
        this.payQrcodeUrl = res;
        
      });
    },
    checkPayStatus(id){
      getPayment(id).then((res) => {
        if (res.code == 200 && res.data.status == 1) {
          clearInterval(this.checkPayStatusTask);
          this.msgSuccess("支付成功");
          this.open = false;
          this.getList();
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除订单管理编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delOrder(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有订单管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportOrder(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        })
    },
    handleReceiveOrder(row){
      this.$confirm('是否确认选择该接单人?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          selectReceive(row).then(response => {
            this.msgSuccess("订单确认成功");
            this.getList();
          });
        })
      
    }
  }
};
</script>
